package com.lagou.service.impl;

import com.lagou.pojo.AuthCode;
import com.lagou.service.AuthCodeService;
import com.lagou.service.CodeService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private AuthCodeService authCodeService;

    @Override
    public Integer validateCode(String email, String code) {
        AuthCode authCode = authCodeService.findOneByEmailAndCode(email, code);
        if(authCode == null)
            return 1;
        long currentTimeMillis = System.currentTimeMillis();
        long time = authCode.getExpiretime().getTime();
        if(currentTimeMillis > time)
            return 2;
        return 0;
    }
}
